<?php
  /**
    Returns an array containing each of the sub-strings from text that
    are between openingMarker and closingMarker. The text from 
    openingMarker and closingMarker are not included in the result.
    This function does not support nesting of markers.
  */
  function returnSubstrings($text, $openingMarker, $closingMarker) {
    $openingMarkerLength = strlen($openingMarker);
    $closingMarkerLength = strlen($closingMarker);

    $result = array();
    $position = 0;
    while (($position = strpos($text, $openingMarker, $position)) !== false) {
      $position += $openingMarkerLength;
      if (($closingMarkerPosition = strpos($text, $closingMarker, $position)) !== false) {
        $result[] = substr($text, $position, $closingMarkerPosition - $position);
        $position = $closingMarkerPosition + $closingMarkerLength;
      }
    }
    return $result;
  }
  
  // Example:
  $exampleText = "565656<b>bonjour</b> � tous, <b>comment</b> allez-vous ?";
  $result = returnSubstrings($exampleText, "<b>", "</b>");
  var_export($result);
  
  // Prints:
  // array (
  //   0 => 'bonjour',
  //   1 => 'comment',
  // )
?> 

